<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<script src="https://g.alicdn.com/dingding/dingtalk-jsapi/2.7.13/dingtalk.open.js"></script>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<!-- *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* header end    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -->
</head>
<body>
    <!-- *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* content start *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* -->
        欢迎来到主页123
    <!-- <input type="button" value="上传文件"  id="choose-file"/> -->
    <form id="myform">
        <input type="hidden" name="code" id="code">
        test1:<input type="text" name="test1">
        <br/>
        test2:<input type="text" name="test2">
        <br/>
        <input type="file" name="file">
        <br/>
        <input type="button" id="upload" value="新增">
    </form>
    
    <a href="/province">跳转到审批列表</a>
    <!-- *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* content end   *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* -->
</body>
<script type="text/javascript" th:inline="javascript">
$.get('/getJsTicket',{url:location.href},function(data,status){
    alert(JSON.stringify(data));
    if( !data.success ){
        return;
    }
    var config = data.result;
    dd.config({
        agentId: config.agentId, // 必填，微应用ID
        corpId: config.corpId,//必填，企业ID
        timeStamp: config.timeStamp, // 必填，生成签名的时间戳
        nonceStr: config.nonceStr, // 必填，生成签名的随机串
        signature: config.signature, // 必填，签名
        type:0,   //选填。0表示微应用的jsapi,1表示服务窗的jsapi；不填默认为0。该参数从dingtalk.js的0.8.3版本开始支持
        jsApiList : [
            'runtime.info',
            'biz.contact.choose',
            'device.notification.confirm',
            'device.notification.alert',
            'device.notification.prompt',
            'biz.ding.post',
            'biz.util.openLink',
            'biz.util.uploadAttachment',
            'biz.cspace.preview'
        ] // 必填，需要使用的jsapi列表，注意：不要带dd。
    });
    
    dd.ready(function() {
        $("#upload").click(function(){
            dd.runtime.permission.requestAuthCode({
                corpId: config.corpId, // 企业id
                onSuccess: function (info) {
                    var code = info.code // 通过该免登授权码可以获取用户身份
                    $("#code").val(code);
                    var formData = new FormData(document.querySelector("#myform"));//获取form值
                    $.ajax({
                        url: "/upload",
                        type: "POST",
                        data: formData,
                        processData: false,  // 不处理数据
                        contentType: false,   // 不设置内容类型
                        success:function(data){
                            if (data.success){
                                alert(JSON.stringify(data.result));
                                var config = data.result;
                                dd.biz.cspace.preview({
                                    corpId:"ding9aa3d69141ac46cc35c2f4657eb6378f",
                                    spaceId:config.spaceld,
                                    fileId:config.fileld,
                                    fileName:config.fileName,
                                    fileSize:config.fileSize,
                                    fileType:config.fileType,
                                    onSuccess: function() {
                                        //无，直接在native显示文件详细信息
                                    },
                                    onFail: function(err) {
                                        // 无，直接在native页面显示具体的错误
                                        alert(JSON.stringify(err));
                                    }
                                });
                            }else{
                                alert(data.message);
                            }
                        }
                    });
                    
                    
                }
            });
        });
        
        /* dd.biz.cspace.preview({
            corpId:"ding9aa3d69141ac46cc35c2f4657eb6378f",
            spaceId:"1836440817",
            fileId:"10598464098",
            fileName:"adb(2).bat",
            fileSize:76,
            fileType:"bat",
            onSuccess: function() {
                //无，直接在native显示文件详细信息
            },
            onFail: function(err) {
                // 无，直接在native页面显示具体的错误
                alert(JSON.stringify(err));
            }
        }); */
        // 2019年12月12日 16:23:06 spaceid是后台获取，后面代码不需要了
        return;
        // 获取spaceid
        $.get("/grantCustomSpace",function(data,status){
            if (data.success){
                var spaceId = data.result;
                alert(spaceId);
                $("#choose-file").click(function(){
                    dd.biz.util.uploadAttachment({
                        image:{multiple:true,compress:false,max:9,spaceId: spaceId},
                        space:{corpId:"ding9aa3d69141ac46cc35c2f4657eb6378f",spaceId:spaceId,isCopy:1 , max:9},
                        file:{spaceId:spaceId,max:1},
                        types:["photo","camera","file","space"],//PC端支持["photo","file","space"]
                        onSuccess : function(result) {
                           var type = result.type;
                           var data = result.data[0];
                           var spaceid = data.spaceId;
                           var fileId = data.fileId;
                           var fileName = data.fileName;
                           var fileSize = data.fileSize;
                           var fileType = data.fileType;
                           alert(type+"|"+spaceid+"|"+fileId+"|"+fileName+"|"+fileSize+"|"+fileType+"|||||||||");
                           // 授权预览
                           $.get("/grantDownload/"+fileId,function(data,status){
                               alert(JSON.stringify(data));
                               dd.biz.cspace.preview({
                                   corpId:"ding9aa3d69141ac46cc35c2f4657eb6378f",
                                   spaceId:spaceid,
                                   fileId:fileId,
                                   fileName:fileName,
                                   fileSize:fileSize,
                                   fileType:fileType,
                                   onSuccess: function() {
                                       //无，直接在native显示文件详细信息
                                   },
                                   onFail: function(err) {
                                       // 无，直接在native页面显示具体的错误
                                       alert(JSON.stringify(err));
                                   }
                               });
                           });
                        },
                        onFail : function(err) {
                            alert("fail"+JSON.stringify(err));
                        }
                    });
                });
            }
            
        });
        
        
        
        
       /*  $.get("/grantDownload/10228543016",function(data,status){
            alert(JSON.stringify(data));
            dd.biz.cspace.preview({
                corpId:"ding9aa3d69141ac46cc35c2f4657eb6378f",
                spaceId:"1836440817",
                fileId:"10228543016",
                fileName:"QQ截图20191122133700.png",
                fileSize:255003,
                fileType:"png",
                onSuccess: function() {
                    //无，直接在native显示文件详细信息
                },
                onFail: function(err) {
                    // 无，直接在native页面显示具体的错误
                    alert(JSON.stringify(err));
                }
            });
        }); */
    });
});

</script>
</html>